import { createStore, applyMiddleware } from 'redux'
import reducer from './reducer'
// import thunk from 'redux-thunk'
// import thunk from '../redux-thunk'
import logger from 'redux-logger'
// import promise from 'redux-promise'
import promise from '../redux-promise'
import { craeteSetLoadingAction, craeteSetUsersAction, fetchUsers, fetchUsersPromise } from './action/usersAction'



// 如果使用thunk中间件，一般放到最前面
// const store = applyMiddleware(thunk.withExtraArgument(123), logger)(createStore)(reducer)

// store.dispatch(craeteSetLoadingAction(true)) // 设置用户数据加载状态
// setTimeout(() => { // 异步加载数据
//     store.dispatch(craeteSetUsersAction([
//         { id: 99, name: 'xx', age: 99 },
//         { id: 100, name: 'xxy', age: 999 }
//     ]))
//     store.dispatch(craeteSetLoadingAction(false))
// }, 1000)


// store.dispatch(fetchUsers())


const store = applyMiddleware(promise, logger)(createStore)(reducer)
store.dispatch(fetchUsersPromise())